#Maintainer: Tobias Powalowski <tpowa@archlinux.org>

pkgname=capi4hylafax
pkgver=010300
_pkgver=01.03.00
pkgrel=11
pkgdesc="capi plugin for hylafax to enable isdn faxing"
arch=(x86_64)
url="ftp://ftp.avm.de/tools"
license=('GPL')
depends=('glibc' 'isdn4k-utils' 'hylafax' 'gcc-libs' 'libtiff' 'dialog')
source=(https://sources.archlinux.org/other/packages/capi4hylafax/$pkgname-$_pkgver.tar.gz
	config.faxCAPI 
	c2faxrecv.service
	capi4hylafax.conf
        capi4hylafax-compile-gcc48-fix.patch)

install=capi4hylafax.install
backup=(var/spool/hylafax/etc/config.faxCAPI)

prepare() {
  cd $pkgname-$_pkgver
  # fix compiling with gcc48
  patch -Np1 -i $srcdir/capi4hylafax-compile-gcc48-fix.patch
  # fix config file
  sed -i -e 's#/etc/config.faxCAPI#/var/spool/hylafax/etc/config.faxCAPI#g' src/defaults.h.in
  autoreconf --force --install
}

build() {
  cd "$srcdir"/$pkgname-$_pkgver
  ./configure
  make
}

package() {
  cd $pkgname-$_pkgver
  install -m755 -D src/faxsend/c2faxsend "$pkgdir"/usr/bin/c2faxsend
  install -m755 -D src/faxrecv/c2faxrecv "$pkgdir"/usr/bin/c2faxrecv
  install -m755 -D setupconffile "$pkgdir"/usr/bin/c2faxaddmodem
  install -m644 -D "$srcdir"/config.faxCAPI "$pkgdir"/var/spool/hylafax/etc/config.faxCAPI
# adding FIFO
  mkfifo "$pkgdir"/var/spool/hylafax/FIFO.faxCAPI
  chown 10 "$pkgdir"/var/spool/hylafax/FIFO.faxCAPI
  chgrp 14 "$pkgdir"/var/spool/hylafax/FIFO.faxCAPI
  chmod 0600 "$pkgdir"/var/spool/hylafax/FIFO.faxCAPI
# fix /var/spool/hylafax permission
  chown 10 "$pkgdir"/var/spool/hylafax
  chgrp 14 "$pkgdir"/var/spool/hylafax
# adding udev rule
  mkdir -p "$pkgdir"/usr/lib/udev/rules.d
cat << EOF >> "$pkgdir"/usr/lib/udev/rules.d/53-capi4hylafax.rules
# CAPI devices
SUBSYSTEM=="capi", KERNEL=="capi", NAME="capi20", SYMLINK+="isdn/capi20", GROUP="uucp"
SUBSYSTEM=="tty" KERNEL=="capi[0-9]*", NAME="capi/%n", GROUP="uucp"

EOF
# fix c2faxadd
  sed -i -e 's#/etc/config.faxCAPI#/var/spool/hylafax/etc/config.faxCAPI#g' "$pkgdir"/usr/bin/c2faxaddmodem
  echo "main_config_dialog" >>  "$pkgdir"/usr/bin/c2faxaddmodem
# add systemd files
  install -D -m644 $srcdir/c2faxrecv.service $pkgdir/usr/lib/systemd/system/c2faxrecv.service
  install -D -m644 $srcdir/capi4hylafax.conf $pkgdir/usr/lib/modules-load.d/capi4hylafax.conf
}
md5sums=('d37dc652ac80d1525ef8693be55ee67f'
         '653b60695d21c128f020a86274ca9192'
         'e2c085a00189ded0a659642c689a1be2'
         '7c41d4fa5c5ef7b1372813341fd0d02b'
         'fa01597396c5493f90243a8d9e2841c0')
